package structure;

import java.awt.Color;
import java.awt.image.BufferedImage;

import utilities.rle2dUtilities;

public class ImageContainer {
	
	private int width;
	private int heigth;
	
	private BufferedImage bImage;
	
	public ImageContainer (BufferedImage bImage) {
			
		this.width = bImage.getWidth();
		this.heigth	= bImage.getHeight();
		
		this.bImage = bImage;
		
	}
	
	public BufferedImage getBImage() {
		return bImage;
	}

	public int getWidth() {
		return width;
	}

	public void setWidth(int width) {
		this.width = width;
	}

	public int getHeigth() {
		return heigth;
	}

	public void setHeigth(int heigth) {
		this.heigth = heigth;
	}

	public int getRedAt(int x, int y) {
		int pixel = bImage.getRGB(x, y);
		Color pixelColor = new Color (pixel);
		return pixelColor.getRed();
	}
	
	public int getGreenAt(int x, int y) {
		int pixel = bImage.getRGB(x, y);
		Color pixelColor = new Color (pixel);
		return pixelColor.getGreen();
	}
	
	public int getBlueAt(int x, int y) {
		int pixel = bImage.getRGB(x, y);
		Color pixelColor = new Color (pixel);
		return pixelColor.getBlue();
	}
	
	public int getColorComponent(int x, int y, String COLOR_NAME){
		int pixel = bImage.getRGB(x, y);
		Color colorPixel = new Color(pixel);
		
		int retVal = -1;
		
		if(rle2dUtilities.RED_NAME.equals(COLOR_NAME))
			retVal = colorPixel.getRed();
		else if(rle2dUtilities.GREEN_NAME.equals(COLOR_NAME))
			retVal = colorPixel.getGreen();
		else if(rle2dUtilities.BLUE_NAME.equals(COLOR_NAME))
			retVal = colorPixel.getBlue();
		
		return retVal;
	}
	
}

